this.throwMode = 'touch';
var startClientX;
var startClientY;
var toolscount=3;
var gamescount=3;
var equipment="PC";

document.addEventListener('touchmove',
  function(e) {
    var touches = e.touches.item(0);
    if (!startClientX) startClientX = touches.clientX;
    if (!startClientY) startClientY = touches.clientY;
  },
false);

document.addEventListener('touchend',
  function(e) {
    var touches = e.changedTouches.item(0);
    var endClientX = touches.clientX;
    var endClientY = touches.clientY;
    var xMoved = endClientX - startClientX;
    var yMoved = endClientY - startClientY;
    var current_area = window.location.hash ? parseInt(window.location.hash.substr(5)) : 1;
    if (xMoved < -20 && (current_area < $('[data-role=page]').length)) {
        window.location.hash = '#area' + (current_area + 1);
    } else if (xMoved > 20 && current_area > 1) {
        window.location.hash = '#area' + (current_area - 1);
    }
    startClientY = null;
    startClientX = null;
  },
false);

function addGameImageCssById(id,e){
  var pageindex=e.substr(e.length-1,e.length);
  var percent=getPercent(pageindex,gamescount)
  document.getElementById(id).style.left=percent;
}

function getPercent(num,zong) {
  return Math.round(parseFloat(num)/parseFloat(zong)*10000)/100.00+"%"; 
}

(function checkSupport() {
    var ua = navigator.userAgent;
    var iosBrowserPattern = /(iPad|iPod).+OS\s\d/;
    var iphoneBrowserPatern=/(iPhone).+OS\s\d/;
    var androidBrowserPattern = /Android\s(\d)/;
    var matchIos = iosBrowserPattern.exec(ua);
    var matchiphone=iphoneBrowserPatern.exec(ua);
    var matchAndroid = androidBrowserPattern.exec(ua);
    if(/(iPhone|iPod|Android)/i.test(ua)){
      equipment="phone";
    }else if(matchIos && matchIos[1] == 'iPad'){
    equipment="pad";
  }
  
})();

function addMetaFile() {
  var fileref=document.createElement("meta");
  fileref.name = "viewport";
  if ("pad"==equipment) {
    fileref.content="user-scalable=no, width=device-width,initial-scale=1,maximum-scale=1";
  } else {
    fileref.content="initial-scale=0.74,user-scalable=no, width=device-width,target-densitydpi=300dpi,maximum-scale=0.74";
  }
  var headobj = document.getElementsByTagName('head')[0];
  headobj.appendChild(fileref);
}

window.applicationCache.addEventListener('updateready', function(e) {
  if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
    window.applicationCache.swapCache();
    if (confirm('A new version of this site is available. Load it?')) {
      window.location.reload();
    }
  }
}, false);

function forward(action){ 
	window.location.href="jsp/"+action+".jsp"; 
}

$(function(){
    $("#right_games_button").bind('click',function(){
        window.location.href="html5GameShow.jsp"; 
    })
});

$(function(){
    $("#left_tools_button").bind('click',function(){
        window.location.href="html5ToolsShow.jsp"; 
    })
});



